<script setup>
import HomePanel from './HomePanel.vue'
import { getGoodsAPI } from '@/apis/home'
import { onMounted,ref } from 'vue'
const goodsProduct = ref([])
const getGoods = async () => {
  const { result } = await getGoodsAPI()
  goodsProduct.value = result
}
onMounted( ()=> getGoods() )
</script>
<template>
    <div class="home-product">
      <HomePanel :title="cate.name" v-for="cate in goodsProduct" :key="cate.id">
          <template #main>
        <div class="box">
          <div class="cover">
            <RouterLink to="/">
              <img :src="cate.picture" alt="" />
              <strong class="label">
                <span>{{ cate.name }}馆</span>
                <span>{{ cate.saleInfo }}</span>
              </strong>
            </RouterLink>
          </div>
          <ul class="goods-list">
            <li v-for="goods in cate.goods" :key="goods.id" class="goods-item">
              <RouterLink to="/">
                <img :src="goods.picture" alt="" />
                <p class="name ellipsis">{{ goods.name }}</p>
                <p class="desc ellipsis">{{ goods.desc }}</p>
                <p class="price">¥{{ goods.price }}</p>
              </RouterLink>
            </li>
          </ul>
        </div>
        </template>
      </HomePanel>
    </div>
  </template>
  
  <style scoped lang='scss'>
  .home-product {
    background: #fff;
    margin-top: 20px;
    
    .box {
      display: flex;
  
      .cover {
  max-width: 240px; /* 设置大图的最大宽度 */
  margin: 0 auto; /* 水平居中 */
  text-align: center; /* 文字居中 */
  position: relative;

  img {
    max-width: 100%; /* 图片宽度最大为容器宽度 */
    max-height: 100%; /* 图片高度最大为容器高度 */
    height: auto; /* 根据宽度等比缩放高度 */
  }
}


.label {
  width: 188px;
  height: 66px;
  display: flex;
  font-size: 18px;
  color: #fff;
  line-height: 66px;
  font-weight: normal;
  position: absolute;
  left: 50%; /* 水平居中 */
  top: 50%; /* 垂直居中 */
  transform: translate(-50%, -50%); /* 使用transform来实现居中 */
}
          span {
            text-align: center;
  
            &:first-child {
              width: 76px;
              background: rgba(0, 0, 0, 0.9);
            }
  
            &:last-child {
              flex: 1;
              background: rgba(0, 0, 0, 0.7);
            }
          }
        }
      }
  
      .goods-list {
        flex: 1; /* 使得商品列表占据剩余空间 */
        display: flex;
        flex-wrap: wrap;
  
        .goods-item {
          width: 240px;
          height: 300px;
          margin-left: 10px;
          margin-bottom: 10px;
  
          &:nth-last-child(-n + 4) {
            margin-bottom: 0;
          }
  
          &:nth-child(4n) {
            margin-right: 0;
          }
  
          &:hover {
            transform: translate3d(0, -3px, 0);
            box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
          }
  
          img {
            width: 160px;
            height: 160px;
            margin-left: 35px; 
          }
  
          p {
            padding-top: 10px;
            text-align: center; /* 文字居中 */
          }
  
          .name {
            font-size: 16px;
          }
  
          .desc {
            color: #999;
            height: 29px;
          }
  
          .price {
            color: $priceColor;
            font-size: 20px;
          }
        }
      }
  </style>
  